import {
  CoolController,
  BaseController,
  TagTypes,
  CoolUrlTag,
} from '@cool-midway/core';
import { GoodsPromoOrderService } from '../../service/promo_order.service';
import { Body, Inject, Post } from '@midwayjs/core';

/**
 * 促销订单前端
 */
@CoolUrlTag({
  key: TagTypes.IGNORE_TOKEN,
  value: ['createComboOrder', 'createSeckillOrder', 'createBuyGiftOrder'],
})
@CoolController()
export class AppGoodsPromoOrderController extends BaseController {
  @Inject()
  goodsPromoOrderService: GoodsPromoOrderService;

  @Inject()
  ctx;

  /**
   * 创建套餐订单
   */
  @Post('/createComboOrder')
  async createComboOrder(@Body() params: {
    billNo: string;
    remark?: string;
  }) {
    const userId = this.ctx.user.id;
    return this.ok(await this.goodsPromoOrderService.createComboOrder(
      userId,
      params.billNo,
      params.remark
    ));
  }

  /**
   * 创建秒杀订单
   */
  @Post('/createSeckillOrder')
  async createSeckillOrder(@Body() params: {
    billNo: string;
    goodsId: string;
    quantity: number;
    remark?: string;
  }) {
    const userId = this.ctx.user.id;
    return this.ok(await this.goodsPromoOrderService.createSeckillOrder(
      userId,
      params.billNo,
      params.goodsId,
      params.quantity,
      params.remark
    ));
  }

  /**
   * 创建买赠订单
   */
  @Post('/createBuyGiftOrder')
  async createBuyGiftOrder(@Body() params: {
    billNo: string;
    goodsId: string;
    quantity: number;
    remark?: string;
  }) {
    const userId = this.ctx.user.id;
    return this.ok(await this.goodsPromoOrderService.createBuyGiftOrder(
      userId,
      params.billNo,
      params.goodsId,
      params.quantity,
      params.remark
    ));
  }
} 